home *** CD-ROM | disk | FTP | other *** search
- Path: newshost.cin.gov.au!usenet
- From: rossw@cin.gov.au (Ross Wilson)
- Newsgroups: comp.lang.c
- Subject: Re: array of pointers to a tree structure ? ( right post, the other one has a miss * )
- Date: Thu, 11 Jan 1996 06:49:57 GMT
- Organization: Community Information Network
- Message-ID: <4d28c7$gc7@canb.cin.gov.au>
- References: <4d06ge$9lc@hermes.fundp.ac.be>
- NNTP-Posting-Host: chico.cin.gov.au
- X-Newsreader: Forte Free Agent 1.0.82
-
- Francisco Melo Ledermann <fmelo@biq.fundp.ac.be> wrote:
-
- <snip>
- >/* BOXES STRUCTURE FOR THE CONSTRUCTION OF A TREE */
-
- >struct boxes {
- > int number;
- > struct boxes *pointer_1;
- > struct boxes *pointer_2;
- > struct boxes *pointer_3;
- > }
-
- >struct boxes *array_pointers [15];
-
-
- <snip>
- > I have tried statements like this with out
- >success:
-
-
- >(*(array_pointers + 1)).pointer_1 = (array_pointers + 0);
-
- >or
-
- >(array_pointers[1]).pointer_1 = &array_pointers[0];
- >
-
- >Somebody know how can I define a pointer inside the box in the way that
- >it points to a box in the array ???
-
- Francisco,
-
- the main problem appears to be a misunderstanding about
- array_pointers[] and what it contains. array_pointers[] is an array
- of POINTERS TO TYPE STRUCT BOXES, so array_pointers[1] is a pointer to
- type struct boxes. So you can't do this:
-
- (array_pointers[1]).pointer_1 = &array_pointers[0];
-
- since array_pointers[1] is a pointer, not a "struct boxes" object and
- &array_pointers[0] is the address of the pointer to the 0th struct
- boxes, not the struct itself. There are similar problems with the
- other attempt above.
-
- Try this instead:
-
- array_pointers[1]->pointer_1 = array_pointers[0];
-
- Since array_pointer[1] is a pointer to an object of type struct boxes,
- this sets the pointer_1 element of the 1th struct to the address of
- the 0th struct.
-
- Use the A->B form if A is a pointer to something containing B. Use
- the A.B form where A is the actual something containing B.
-
- I am not sure if you just left it out for the posting, but:
-
- struct boxes
- {
- };
-
- needs the semicolon.
-
-
- Good luck,
- Ross
-
-